import Taro from '@tarojs/taro'
import { BASE_URL } from './url'

const fetch = ({
  url = '',
  method = 'GET',
  data = {},
  header = {},
  isNeedAuth = true,
  tips = '正在加载中...'
}) => {
  return new Promise((resolve, reject) => {
    // 提示
    Taro.showLoading({
      title: tips
    })

    Taro.request({
      url: `${BASE_URL}${url}`, //仅为示例，并非真实的接口地址
      method,
      data,
      header,
      success: res => {
        resolve(res)
      },
      fail: err => {
        reject(err)
      },
      complete: () => {
        Taro.hideLoading()
      }
    })
  })
}

export { fetch }
